﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using System.Linq;
namespace Exact_Extension
{
    public partial class DebtorRegisterRpt : DevExpress.XtraReports.UI.XtraReport
    {
        List<ISHCMC_DebtorRegister> ListDebtor;
        ExactDataContext DS;
        public DebtorRegisterRpt(List<ISHCMC_DebtorRegister> _ListDebtor,ExactDataContext _DS)
        {
            InitializeComponent();
            ListDebtor = _ListDebtor;
            DS = _DS;
        }

        private void DebtorRegisterRpt_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            foreach (ISHCMC_DebtorRegister itemDebtor in ListDebtor)
            {
                bindingSource1.DataSource = itemDebtor;
                cellDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                this.cellRegisterdate.Text = DateTime.Now.ToString("dd/MM/yyyy");
                var queryDis = from Dis in DS.ISHCMC_V_DiscountLists
                               where Dis.StudentID == itemDebtor.StudentIDIS
                               select Dis;
                foreach (ISHCMC_V_DiscountList itemDis in queryDis)
                {
                    if (itemDis.DiscountType == "APPF50")
                    {
                        this.chkAPPDis50.Checked = true;
                    }
                    if (itemDis.DiscountType == "APPF100")
                    {
                        this.chkAPPFDis100.Checked = true;
                    }
                    if (itemDis.DiscountType == "TeacherKid")
                    {
                        this.chkStaffDiscount.Checked = true;
                    }
                    if (itemDis.DiscountType == "Sibling2C")
                    {
                        this.chk2ndChild.Checked = true;
                    }
                    if (itemDis.DiscountType == "Sibling3C" || itemDis.DiscountType == "ThirdChild")
                    {
                        this.chk2ndChild.Checked = true;
                    }
                    if (itemDis.DiscountType == "CCC")
                    {
                        this.chkCCList.Checked = true;
                    }
                 
                }
                var queryInvoicePayment = from InvoicePaid in DS.ISHCMC_InvoicePayments
                                          where InvoicePaid.StudentID == itemDebtor.StudentIDIS
                                          select InvoicePaid;
                if (queryInvoicePayment.Count() > 0)
                {
                    decimal PaidAmount = 0;
                    string refno = "";
                    DateTime PaidDate = DateTime.Now;
                    foreach (ISHCMC_InvoicePayment itemInvoicePayment in queryInvoicePayment)
                    {
                        PaidAmount += itemInvoicePayment.PaidAmount.Value;
                        refno += " / " + itemInvoicePayment.ReferenceNo;
                        PaidDate = itemInvoicePayment.PaymentDate.Value;


                    }
                    this.cellPaidAmount.Text = PaidAmount.ToString("#,#");
                    this.cellPaidDate.Text = PaidDate.ToString("dd/MM/yyy");
                    this.cellPaidRef.Text = refno;
                }

            }
        }

    }
}
